package k2_oop.p9_collection.demo12;

public class Poker implements Comparable<Poker> {

    private String type;
    private String value;
    private int typeIndex;
    private int valueIndex;

    public Poker(String type, String value, int typeIndex, int valueIndex) {
        this.type = type;
        this.value = value;
        this.typeIndex = typeIndex;
        this.valueIndex = valueIndex;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public int getTypeIndex() {
        return typeIndex;
    }

    public void setTypeIndex(int typeIndex) {
        this.typeIndex = typeIndex;
    }

    public int getValueIndex() {
        return valueIndex;
    }

    public void setValueIndex(int valueIndex) {
        this.valueIndex = valueIndex;
    }

    @Override
    public String toString() {
        return type+value;
    }

    /**
     * 默认排序规则：先排花色，如果花色相同排数字
     * @param o the object to be compared.
     * @return
     */
    @Override
    public int compareTo(Poker o) {

        int thisTypeIndex = this.typeIndex;
        int thatTypeIndex = o.getTypeIndex();

        int thisValueIndex = this.valueIndex;
        int thatValueIndex = o.getValueIndex();

        if(thisTypeIndex==thatTypeIndex){
            return thisValueIndex-thatValueIndex;
        }else{
            return thisTypeIndex-thatTypeIndex;
        }
    }
}
